package Test;

import java.util.*;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: Administrator
 * \* Date: 2022/4/4
 * \* Time: 17:45
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
public class TestDemo1 {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] stem = new int[m+1];//为了是数组的编号跟石板的下标对应在一块
        //初始化数组
        for(int i=0; i<m+1;i++){
            stem[i] = Integer.MAX_VALUE;//放置一个最大的不可能到达的数字
        }
        stem[n] = 0;//初始化第一块石板为0
        //开始跳跃
        for(int i =0;i<m;i++){
            //如果stem[i]里的数字为初始化哪个的化，跳出循环
            if(stem[i] == Integer.MAX_VALUE){
                continue;
            }
            List<Integer> list = div(i);
            for(int j : list){
                if(i+j<=m && stem[i+j] != Integer.MAX_VALUE){
                    stem[i+j] = Math.min(stem[i+j],stem[i]+1);
                }else if(i+j <= m){
                    stem[i+j] = stem[i]+1;
                }
            }
        }
    }
    //找出所有约数
    public static List<Integer> div(int num){
        List<Integer> list = new ArrayList<Integer>();
        for(int i = 2;i*i<=num; i++){
            if(num % i ==0){
                list.add(i);
                if(num/i != i ){
                    list.add(num/i);
                }
            }
        }
        return list;
    }
}
